package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.land_register;
/**
 * Servlet implementation class landServlet
 */
@WebServlet("/landServlet")
public class landServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public landServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		String id=request.getParameter("account");
		String password=request.getParameter("password");
		String land=new land_register().land(id, password);
		switch(land) {
		case "customer":
			request.getSession().setAttribute("cus_id",id);
			response.sendRedirect("HTML/myOrder.jsp");
			//request.getRequestDispatcher("HTML/myOrder.jsp").forward(request, response);
			break;
		case "admin":
			request.getSession().setAttribute("admin_id",id);
			response.sendRedirect("HTML/admin_order.jsp");
			//request.getRequestDispatcher("HTML/admin_order.jsp").forward(request, response);
			break;
		case "delivery":
			request.getSession().setAttribute("delivery_id",id);
			response.sendRedirect("HTML/delivery.jsp");
			//request.getRequestDispatcher("HTML/delivery.jsp").forward(request, response);
			break;
		case "false":
			response.sendRedirect("HTML/login.html");
			break;
		default:
			break;
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
